package org.hcyspartnoc.demo.dao;

import org.hcyspartnoc.demo.entity.Major;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface MajorDao extends Neo4jRepository<Major,Long> {


    @Query("MATCH (n) WHERE ID(n) = $nodeId DETACH DELETE n")
    void deleteByNodeId(@Param("nodeId") Integer nodeId);


    @Query("""
        MATCH (n) WHERE ID(n) = $nodeId
        SET n.name = CASE WHEN $name IS NOT NULL THEN $name ELSE n.name END,
            n.number = CASE WHEN $number IS NOT NULL THEN $number ELSE n.number END,
            n.value = CASE WHEN $value IS NOT NULL THEN $value ELSE n.value END
        RETURN n
    """)
    void updateNode(
            @Param("nodeId") Integer nodeId,
            @Param("name") String name,
            @Param("number") String number,
            @Param("value")String value);
}
